const Router = require("koa-router");

const {
  create,
  detail,
  list,
  update,
  remove,
  addLabels,
  fileInfo,
} = require("../controller/moment.controller");
// 验证token（是否登录）
const {
  verifyAuth,
  verifyPermission,
} = require("../middleware/auth.middleware");
const { verifyLabelExists } = require("../middleware/label.middleware");
const momentRouter = new Router({ prefix: "/moment" });

momentRouter.post("/", verifyAuth, create);
// 查看文章详请是不需要登录的
momentRouter.get("/:momentId", detail);
// 修改某个动态

//分页查询多条数据
momentRouter.get("/", list);
// 1.用户必须登录 2.用户查看自己的权限
momentRouter.patch("/:momentId", verifyAuth, verifyPermission, update);

// 删除某个动态
momentRouter.delete("/:momentId", verifyAuth, verifyPermission, remove);

// 给动态添加标签
momentRouter.post(
  "/:momentId/labels",
  verifyAuth,
  verifyPermission,
  verifyLabelExists,
  addLabels
);

// 动态配图的服务
momentRouter.get("/images/:filename", fileInfo);

module.exports = momentRouter;
